Completed
Push — master ( c9464c...79644f )
by Wallace
01:43
created

database.test.js ➔ ... ➔ it(ꞌexpect to be an object and contains searchꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
1
/**
2
 * Database test
3
 */
4
'use strict'
5
6
const path = require('path')
7
const chai = require('chai')
8
const expect = chai.expect
9
10
chai.use(require('chai-fs'))
11
12
const database = require('../bin/database')
13
14
const file = path.join(__dirname, '../test/files/db.json')
15
const db = database.setFile(file)
16
17
describe('Test database', function () {
18
  before(function () {
19
    db.add('subtitle', 'pob').store()
20
    db.addEnv({'MOOV_SEARCH': 'dope'})
21
  });
22
23
  it ('expect to return an error if file is not a json', function () {
24
    expect(() => { database.setFile('../db.txt') }).to.throw('The database file must be a json file')
25
  })
26
27
  it ('expect database to be a string and equal parameter', function () {
28
    expect(db.database)
29
      .to.be.a('string')
30
      .to.be.equal(file)
31
  })
32
33
  it ('expect to be an object and contains subtitle property', function () {
34
    expect(db.add('subtitle', 'pob').data)
35
      .to.be.an('object')
36
      .to.have.property('subtitle', 'pob')
37
  })
38
39
  it ('expect file to exists and is a json', function () {
40
    expect(file)
41
      .to.be.a.file()
42
      .with.json
43
  })
44
45
  it ('expect an error if file can\'t be created', function () {
46
    expect(database.setFile('/home/db.json').add('key', 'value').store())
47
      .to.be.an.error
48
  })
49
50
  it ('expect to be an empty object', function () {
51
    database.setFile('/home/db.json').data = {}
52
53
    expect(database.setFile('/home/db.json').get())
54
      .to.be.an('object')
55
      .to.be.empty
56
  })
57
58
  it ('expect to be an not empty object', function () {
59
    expect(database.setFile(file).get())
60
      .to.be.an('object')
61
      .to.not.empty
62
  })
63
64
  it ('expect to be an object and contains subtitle', function () {
65
    expect(db.get())
66
      .to.be.an('object')
67
      .to.have.property('subtitle', 'pob')
68
  })
69
70
  it ('expect to be a string and is equal pob', function () {
71
    expect(db.get('subtitle'))
72
      .to.be.an('string')
73
      .to.be.equal('pob')
74
  })
75
76
  it ('expect an error if key don\'t exists in file', function () {
77
    expect(() => { db.get('potatoes') })
78
      .to.throw('potatoes is undefined')
79
  })
80
81
  it ('expect an error if typeof is not a object', function () {
82
    expect(() => { db.massive('test') })
83
      .to.throw('data must be an object')
84
  })
85
86
  it ('expect to be an object', function () {
87
    expect(db.massive({'subtitle': 'pob', 'quality': '720p'}).data)
88
      .to.be.an('object')
89
      .to.have.property('subtitle')
90
  })
91
92
  it ('expect an error if parameter is not a object', function () {
93
    expect(() => { db.addEnv('test') })
94
      .to.throw('data must be an object')
95
  })
96
97
  it ('expect to be an object and contains search', function () {
98
    expect(process.env)
99
      .to.be.an('object')
100
      .to.have.property('MOOV_SEARCH')
101
  })
102
})
103